package org.cloud.im.admin.account.controller;

import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.cloud.im.admin.account.ao.AccountQueryAO;
import org.cloud.im.admin.account.ao.LoginAO;
import org.cloud.im.admin.account.service.IAccountService;
import org.cloud.im.admin.common.Result;
import org.cloud.im.admin.common.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @Author: w.weidong.lin
 * @Description: 账号表 接口
 * @Date: create in 2021-10-26 10:35:17
 */
@Slf4j
@RestController
@RequestMapping("/im/account")
public class AccountController {

    @Autowired
    @Qualifier(value = "im.AccountServiceImpl")
    private IAccountService iAccountService;

    /**
     * 查询列表
     */
    @GetMapping("/list")
    @ResponseBody
    public Result<TableDataInfo> list(AccountQueryAO queryAO) {
        return Result.getSuccessResult(iAccountService.getList(queryAO));
    }


    /**
     * 组织员工信息初始化，
     * <p>
     * TODO 前期方面测试，用excel导入初始化员工账号新，放内存处理
     *
     * @return
     */
    @GetMapping("/initOrgUserInfo")
    @ResponseBody
    public Result initOrgUserInfo() {

        String inputFilePath = "D:\\storage\\im\\组织结构员工信息.xlsx";
        return iAccountService.initOrgUserInfo(inputFilePath);
    }

    /**
     * 登录
     *
     * @param loginAO
     * @return
     */
    @PostMapping("/login")
    public Result login(@RequestBody LoginAO loginAO) {
        log.error(JSON.toJSONString(loginAO));
        return iAccountService.login(loginAO);
    }

    /**
     * 登录
     *
     * @return
     */
    @PostMapping("/update")
    public Result update() {
        return Result.getSuccessResult(iAccountService.update("admin", "东"));
    }

    /**
     * 获取用户群组信息
     *
     * @return
     */
    @GetMapping("/getUserGroup")
    @ResponseBody
    public Result getUserGroup(@RequestParam("userId") String userId) {
        return Result.getSuccessResult(iAccountService.getUserGroup(userId));
    }

}
